<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-divider>基本信息</a-divider>
        <a-row :gutter="48">
          <a-col :span="8" :hidden="true">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
              <a-input :max-length="255" :disabled="formDisabled" v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billNo">
              <a-input v-model="model.billNo" :max-length="36" placeholder="请输入单据编号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <a-input v-model="model.createTime" :max-length="36" placeholder="请选择申请时间" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <select-user-by-dep :multi="false" v-model="model.proposer" disabled></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <j-select-depart v-model="model.proposerDeptId" disabled />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-divider>项目信息</a-divider>
        <a-row :gutter="48">
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <a-input
                v-if="formDisabled"
                readOnly
                @click.prevent="onDetail(model.projectId)"
                v-model="model.projectName"
                style="color: #1890FF; cursor: pointer;"
                placeholder="请选择项目名称"></a-input>
              <select-project-input
                v-else
                ref="projectInput"
                :disabled="formDisabled"
                v-model="model.projectId"
                :proDisabled="true"
                :allowClear="false"
                placeholder="请输入选择项目"
                :projectStatus="'2'"
                @input="projectChangeHandle" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectNo">
              <a-input v-model="model.projectNo" :max-length="36" placeholder="请输入项目编号" disabled></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="签订单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signUnit">
              <select-Company-input v-model="model.signUnit" placeholder="请选择签订单位" disabled />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="managementTeam">
              <select-team-input
                v-model="model.managementTeam"
                :tdlx="1"
                disabled
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
              <select-user-by-dep :multi="false" v-model="model.undertaker" disabled></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目地址" :labelCol="labelCol" :wrapperCol="wrapperCol" style="height:75px" prop="projectAddress">
              <a-form-model-item :style="{display:'inline-block',width:'48%'}" prop="projectAddress">
                <AddressChoice type="cascader" v-model="model.area" placeholder="请输入省市区" disabled/>
              </a-form-model-item>
              <a-form-model-item
                :style="{'margin-top':'0px','margin-left':'5px',display:'inline-block',width:'50%'}"
                prop="projectAddress">
                <a-input v-model="model.projectAddress" placeholder="请输入项目详细地址" disabled></a-input>
              </a-form-model-item>
            </a-form-model-item>

          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessName">
              <!--              <select-task-file-for-project-archive-input :disabled=formDisabled v-model="model.businessName" :allowClear="false" :projectId="model.projectId" :isShowCategoryName="true" :isExcludeWaitingStatus="true" @input="taskChangeBackHandle"/>-->
              <SelectTaskFileInput
                :disabled="formDisabled"
                v-model="model.businessName"
                :allowClear="false"
                :projectId="model.projectId"
                :isShowCategoryName="true"
                :isProjectArchive="true"
                :isExcludeWaitingStatus="true"
                @input="taskChangeBackHandle" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="任务编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskNo">
              <a-input v-model="model.taskNo" :max-length="36" placeholder="请输入任务编号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="实施部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="implementationDepartment">
              <j-select-depart v-model="model.implementationDepartment" disabled/>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionTeam">
              <select-team-input
                
                v-model="model.productionTeam"
                :tdlx="1"
                disabled
              />
              <!--              <a-input :disabled=formDisabled v-model="model.productionTeam" placeholder="请输入生产团队" disabled  ></a-input>-->
              <!--              <a-input :hidden="true" :disabled=formDisabled v-model="model.productionTeamId" placeholder="请输入生产团队" disabled  ></a-input>-->
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="项目负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectLeader">
              <select-user-by-dep
                v-model="model.projectLeader"
                disabled/>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="行业类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryCategory">
              <!--              <a-input :disabled=formDisabled v-model="model.industryCategory" :max-length="36"  placeholder="请输入行业类别"  disabled></a-input>-->
              <j-dict-select-tag
                type="list"
                v-model="model.industryCategory"
                dictCode="industry_category"
                placeholder="请选择行业类别"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="审批级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalLevel">
              <a-input v-model="model.approvalLevel" :max-length="36" placeholder="请输入审批级别" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="审批机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalAuthority">
              <a-input :disabled="formDisabled" v-model="model.approvalAuthority" :max-length="36" placeholder="请输入审批机构" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="投资额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="investmentAmount">
              <a-input-number
                :disabled="formDisabled"
                :max="999999999"
                :min="0"
                :precision="2"
                v-model="model.investmentAmount"
                placeholder="请输入投资额(元)"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="规模" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scale">
              <a-input :disabled="formDisabled" v-model="model.scale" :max-length="36" placeholder="请输入规模" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="批复文号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalDocumentNo">
              <a-input :disabled="formDisabled" v-model="model.approvalDocumentNo" :max-length="36" placeholder="请输入批复文号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="批复日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalDate">
              <j-date :disabled="formDisabled" placeholder="请选择批复日期" v-model="model.approvalDate" style="width: 100%" />
            </a-form-model-item>
          </a-col>

          <template v-if="model.archiveMajorCategory ">
            <!--            <a-col :span="8">-->
            <!--              <a-form-model-item label="档案大类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveMajorCategory">-->
            <!--                <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.archiveMajorCategory" dictCode="sys_category,name,id,pid = '1655763364338606082'" placeholder="请选择档案大类" @input="archiveMajorCategoryInputHandle" />-->
            <!--              </a-form-model-item>-->
            <!--            </a-col>-->
            <!--            <a-col :span="8">-->
            <!--              <a-form-model-item label="档案小类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveMinorCategory">-->
            <!--                <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.archiveMinorCategory" :dictCode="`sys_category,name,id,pid = '${model.archiveMajorCategory}'`" placeholder="请选择档案小类" />-->
            <!--              </a-form-model-item>-->
            <!--            </a-col>-->
            <a-col :span="8">
              <a-form-model-item label="档案大类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveMajorCategory">
                <j-dict-select-category
                  :disabled="formDisabled"
                  v-model="model.archiveMajorCategory"
                  placeholder="请选择档案大类"
                  parentCode="A04"
                  removeCode="A04A02,A04A01"
                  :async="true"
                  @input="modifyCategory"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="档案小类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveMinorCategory">
                <j-dict-select-category :disabled="formDisabled || !model.archiveMinorCategory" v-model="model.archiveMinorCategory" placeholder="请选择档案小类" :parentCode="model.archiveMajorCategory" :async="true"/>
              </a-form-model-item>
            </a-col>

            <a-col :span="8">
              <a-form-model-item label="档案所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveBelongingTeam">
                <select-team-input
                  :disabled="formDisabled"
                  v-model="model.archiveBelongingTeam"
                  :tdlx="1"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="密级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="secrecyLevel">
                <!--                <a-input :disabled=formDisabled v-model="model.secrecyLevel" :max-length="36"  placeholder="请输入密级"  ></a-input>-->
                <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.secrecyLevel" dictCode="secrecy_level" placeholder="请选择密级" />
              </a-form-model-item>
            </a-col>
          </template>
        </a-row>
        <a-divider>存档信息</a-divider>
        <a-row :gutter="48">
          <erp-project-archive-info-list ref="projectArchiveInfo" :disabled="formDisabled" />
        </a-row>

        <a-divider>任务附件</a-divider>
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachments">
              <j-upload :disabled="formDisabled" v-model="model.attachments"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>

        <!-- <a-row :gutter="48">
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row> -->

      </a-form-model>
      <!-- <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list> -->
    </j-form-container>

    <a-row type="flex" justify="center">
      <a-col :span="24">
        <!-- 流程历史跟踪 -->
        <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData"></common-flow-list>
      </a-col>
      <a-col :span="24" style="text-align: center;margin-top: 15px">
        <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
        <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">提 交</a-button>
      </a-col>
    </a-row>
    <!-- 项目详情开始 -->
    <erp-project-report-modal ref="projectModalForm"></erp-project-report-modal>
    <!-- 项目详情结束 -->
    <ErpProjectArchiveFormPrint v-if="formBpm" id="printContent" class="print_style" :formData="model" :formDataHistory="formData"></ErpProjectArchiveFormPrint>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue, viewFile } from '@/utils/util'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectTaskFileForProjectArchiveInput from '@/views/scy/components/SelectTaskFileForProjectArchiveInput'
  import SelectTaskFileInput from '@/views/scy/components/SelectTaskFileInput'
  import SelectProjectTaskInput from '@/views/scy/components/SelectProjectTaskInput.vue';
  import AddressChoice from '@/components/AddressChoice/AddressChoice';
  import JDictSelectCategory from '@/components/dict/JDictSelectCategory.vue'
  import moment from 'moment'
  import { mapGetters } from 'vuex'
  import ErpProjectArchiveInfoList from '../ErpProjectArchiveInfoList.vue';
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'

  import ViewFileModal from '@/views/scy/components/ViewFileModal';
  import CommonFlowList from '@/views/components/CommonFlowList.vue';
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
  import ErpProjectArchiveFormPrint from './ErpProjectArchiveFormPrint'
  import Print from '@/utils/print/printarea.js';

  export default {
    name: 'ErpProjectArchiveForm',
    mixins: [viewFile],
    components: {
      ErpProjectArchiveInfoList,
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      SelectCustomerInput,
      SelectProjectInput,
      SelectTaskFileForProjectArchiveInput,
      SelectProjectTaskInput,
      AddressChoice,
      ViewFileModal,
      CommonFlowList,
      JDictSelectCategory,
      ErpProjectReportModal,
      ErpProjectArchiveFormPrint,
      SelectTaskFileInput
    },
    props: {
      // 流程表单data
      formData: {
        type: Object,
        default: () => {},
        required: false
      },
      // 表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model: {
        },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        confirmLoading: false,
        validatorRules: {
          projectId: [
            { required: true, message: '请选择项目名称!' }
          ],
          businessName: [
            { required: true, message: '请选择业务名称!' }
          ],
          archiveMajorCategory: [
            { required: true, message: '请选择档案大类!' }
          ],
          archiveMinorCategory: [
            { required: true, message: '请选择档案小类!' }
          ],
          archiveBelongingTeam: [
            { required: true, message: '请选择档案所属团队!' }
          ],
          secrecyLevel: [
            { required: true, message: '请选择密级!' }
          ]
        },
        url: {
          add: '/api/erp/omc/projectarchive/erpProjectArchive/add',
          edit: '/api/erp/omc/projectarchive/erpProjectArchive/edit',
          queryById: '/api/erp/omc/projectarchive/erpProjectArchive/queryById',
          getBillNo: '/api/erp/omc/projectarchive/erpProjectArchive/getBillNo',
          queryProjectById: '/api/erp/project/report/erpProjectReport/queryById'
        },
        dictOptions: {},
        projectIdBackups: null
      }
    },
    computed: {
      formDisabled() {
        if (this.formBpm === true) {
          if (this.formData.disabled === false) {
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton() {
        if (this.formBpm === true) {
          if (this.formData.disabled === false) {
            return true
          }
        }
        return false
      }
    },
    created () {
       // 备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      // 如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
      // 加载数据字典信息
      this.initDictConfig();
    },
    methods: {
      ...mapGetters(['userInfo']),

      initDictConfig() {
        initDictOptions('erp_omc_project_task,category_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'businessName', res.result)
          }
        })
        initDictOptions('erp_omc_project,project_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectId', res.result)
          }
        })
      },

      // 修改大类，清空小类
      modifyCategory(data) {
        if (data) {
          if (this.model.archiveMinorCategory) {
            this.$set(this.model, 'archiveMinorCategory', null);
          }
        }
      },

      add () {
        this.edit(this.modelDefault);
        this.model.proposer = this.userInfo().empId;
        this.model.proposerDeptId = this.userInfo().deptId;
        this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
        this.getBillNo();

        this.projectIdBackups = null
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);

        if (this.model.id) {
          this.$refs.projectArchiveInfo.loadData(1, this.model.id)
        } else {
          this.$refs.projectArchiveInfo.dataSource = []
        }
        // 如果有项目id说明是编辑页面，就把原始id给它
        if (this.model.projectId) {
          this.projectIdBackups = this.model.projectId
        }

        this.visible = true;
      },
      // 渲染流程表单数据
      showFlowData() {
        if (this.formBpm === true) {
          let params = { id: this.formData.dataId };
          getAction(this.url.queryById, params).then((res) => {
            if (res.success) {
              this.edit(res.result);
            }
          });
        }
      },

      // 项目选择回调
      async projectChangeHandle({ choseObj }) {
        let backItem = choseObj[0]
        if (!this.projectIdBackups) {
          this.projectIdBackups = this.model.projectId
          // 带出项目编号
          this.$set(this.model, 'projectNo', backItem.finalNo)

          // 带出项目真实名称
          this.$set(this.model, 'projectName', backItem.projectName)

          // 带出签订单位
          this.$set(this.model, 'signUnit', backItem.signUnit)

          // 带出项目承接人
          this.$set(this.model, 'undertaker', backItem.undertaker)

          // 带出经营团队
          this.$set(this.model, 'managementTeam', backItem.oldTeamId ? backItem.oldTeamId : backItem.teamName)

          // 带出项目地址
          this.$set(this.model, 'area', backItem.areaCode)

          // 带出项目地址
          this.$set(this.model, 'projectAddress', backItem.projectAddress)
        }
        // 切换项目清空子表弹窗提示
        if (this.projectIdBackups && this.projectIdBackups !== backItem.id) {
          // if (detailList.length > 0){
          const that = this;
          this.$confirm({
            title: '确认切换项目',
            content: '切换项目会清空所有任务相关信息，您确定要切换吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: async function () {
              // 确认后进行改变
              that.projectIdBackups = that.model.projectId

              // 清空所有带出数据
              that.resetData();

              // 带出项目编号
              that.$set(that.model, 'projectNo', backItem.finalNo)

              // 带出项目真实名称
              that.$set(that.model, 'projectName', backItem.projectName)

              // 带出签订单位
              that.$set(that.model, 'signUnit', backItem.signUnit)

              // 带出项目承接人
              that.$set(that.model, 'undertaker', backItem.undertaker)

              // 带出经营团队
              that.$set(that.model, 'managementTeam', backItem.oldTeamId ? backItem.oldTeamId : backItem.teamName)

              // 带出项目地址
              that.$set(that.model, 'area', backItem.areaCode)

              // 带出项目地址
              that.$set(that.model, 'projectAddress', backItem.projectAddress)
            },
            onCancel() {
              that.model.projectId = that.projectIdBackups
            }
          });
        }
      },
      // 清除所有带出数据
      resetData() {
        // 带出项目编号
        this.$set(this.model, 'projectNo', '')

        // 带出项目真实名称
        this.$set(this.model, 'projectName', '')

        // 带出签订单位
        this.$set(this.model, 'signUnit', '')

        // 带出项目承接人
        this.$set(this.model, 'undertaker', '')

        // 带出经营团队
        this.$set(this.model, 'managementTeam', '')

        // 带出项目地址
        this.$set(this.model, 'area', '')

        // 带出项目地址
        this.$set(this.model, 'projectAddress', '')

        // 清除业务分类
        this.$set(this.model, 'businessName', '')

        // 带出任务编号
        this.$set(this.model, 'taskNo', '')

        // 带出实施部门
        this.$set(this.model, 'implementationDepartment', '')

        // 带出生产团队
        this.$set(this.model, 'productionTeam', '')

        // 带出项目负责人
        this.$set(this.model, 'projectLeader', '')

        // 带出行业类别
        this.$set(this.model, 'industryCategory', '')

        // 带出审批级别
        this.$set(this.model, 'approvalLevel', '')
      },

      // 业务名称选择回调
      taskChangeBackHandle(item) {
        let task = item.choseObj[0];
        if (task) {
          // 带出任务编号
          this.$set(this.model, 'taskNo', task.billNo)

          // 带出实施部门
          this.$set(this.model, 'implementationDepartment', task.executeDepart)

          // 带出生产团队
          this.$set(this.model, 'productionTeam', task.productTeam)

          // 带出项目负责人
          this.$set(this.model, 'projectLeader', task.projectLeading)

          // 带出行业类别
          this.$set(this.model, 'industryCategory', task.industryCategory)

          // 带出审批级别
          this.$set(this.model, 'approvalLevel', task.approvalLevel)
        }
      },

      // 大类切换
      archiveMajorCategoryInputHandle(value) {
        // 清空小类
        this.$set(this.model, 'archiveMinorCategory', '')
      },

      // 获取编号
      getBillNo() {
        let that = this;
        getAction(this.url.getBillNo, {}).then((res) => {
          if (res.success) {
            let data = res.result.records || res.result
            this.$set(this.model, 'billNo', data);
            // this.$set(this.model, 'bpmBizTitle', this.userInfo().employee.name+'-'+data);
          }
        })
      },

      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectById, { id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectModalForm.getDetail(model);
              that.$refs.projectModalForm.title = '项目一览表';
            }
          })
        })
      },

      submitForm(type) {
        const that = this;
        if (type == 'draft') {
          // 代表保存草稿不做校验
          this.submit(type)
        } else if (type == 'submit') {
          // 触发表单验证
          this.$refs.form.validate(valid => {
            let details = this.$refs.projectArchiveInfo.submitForm();
            if (!details.length > 0) {
              this.$message.warning('请添加存档信息！');
              this.$emit('unButtonDisable');
              return
            }
            if (valid) {
              that.submit(type)
            } else {
              that.$emit('unButtonDisable')
            }
          })
        } else {
          console.log('传参数，保存：draft，提交：submit')
        }
      },
      submit (type) {
        const that = this;
        let details = this.$refs.projectArchiveInfo.submitForm();
        var projectName = filterMultiDictText(this.dictOptions['projectId'], this.model.projectId + '')
        var businessName = filterMultiDictText(this.dictOptions['businessName'], this.model.businessName + '')
        this.$set(this.model, 'bpmBizTitle', '项目存档申请单 - ' + (this.model.projectId ? projectName + ' - ' : '') + (this.model.businessName ? businessName + ' - ' : '') + this.userInfo().employee.name + ' - ' + moment(this.model.createTime).format('YYYY-MM-DD'));
        that.confirmLoading = true;
        let httpurl = '';
        let method = '';
        if (!this.model.id) {
          httpurl += this.url.add;
          method = 'post';
        } else {
          httpurl += this.url.edit;
          method = 'put';
        }
        this.model.details = details || []
        httpAction(httpurl, this.model, method).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            if (method == 'post') {
              that.model.id = res.result;
            }
            that.$emit('ok', type, that.model);
          } else {
            that.$message.warning(res.message);
            that.$emit('unButtonDisable');
          }
        }).catch((error) => {
          that.$emit('unButtonDisable', error);
        }).finally(() => {
          that.confirmLoading = false;
        })
      },
      // 点击打印
      onPrint () {
        let print = new Print({
          el: '#printContent',
          popTitle: '项目存档申请单详情 · 禾美环保',
          endCallback() {

          }
        })
      }
    }
  }
</script>
